package com.sunda.spmsuser.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmsuser.entity.SpmsUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

/**
 * <p>
 * SPMS用户信息表 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-01-25
 */
@Mapper
@Component
public interface SpmsUserMapper extends BaseMapper<SpmsUser> {

    @Select("SELECT u.WORK_CODE AS \"userId\",\n" +
            "  u.LOGIN_PASSWORD AS \"loginPassword\",\n" +
            "  u.WORK_ID AS \"workId\",\n" +
            "  u.LAST_NAME AS \"lastName\",\n" +
            "  u.TELEPHONE AS \"telephone\",\n" +
            "  u.MOBILE AS \"mobile\",\n" +
            "  u.EMAIL AS \"email\",\n" +
            "  u.POSITION_ID AS \"positionId\",\n" +
            "  u.POSITION_NAME AS \"positionName\",\n" +
            "  u.DEPT_ID AS \"deptId\",\n" +
            "  u.DEPT_NAME AS \"deptName\",\n" +
            "  u.SUBCOMPANY_ID AS \"subcompanyId\",\n" +
            "  u.SUBCOMPANY_NAME AS \"subcompanyName\",\n" +
            "  u.COMPANY AS \"company\",\n" +
            "  u.BRANCH_POINT AS \"branchPoint\",\n" +
            "  u.BRANCH_LINE AS \"branchLine\",\n" +
            "  u.MANAGER_ID AS \"managerId\",\n" +
            "  u.MANAGER_NAME AS \"managerName\",\n" +
            "  u.OA_STATUS AS \"oaStatus\",\n" +
            "  u.SPMS_STATUS AS \"spmsStatus\"\n" +
            "FROM SPMS_USER u WHERE u.WORK_CODE = #{userId}")
    SpmsUser getByUserId(@Param("userId") String userId);

    @Update("UPDATE SPMS_USER SU SET SU.LOGIN_PASSWORD = #{MDPassword} WHERE SU.WORK_CODE = #{userId}")
    int updatePassword(@Param("userId") String userId, @Param("MDPassword") String MDPassword);
}
